package com.sz.youban.controller.idcard;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.feilong.core.Validator;
import com.sz.youban.controller.base.BaseController;
import com.sz.youban.dt.entity.result.ResultDataEnum;
import com.sz.youban.dt.entity.result.ResultModel;
import com.sz.youban.dt.interfs.idcard.IDtCardIdInfoService;
import com.sz.youban.dt.service.utils.IdcardUtil;


@RestController
@RequestMapping("/idcard")
public class IdCardController  extends BaseController{
	
	@Value("${develop}")
	private boolean develop;
	
	private final Logger log = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private IDtCardIdInfoService cardIdInfoService;
	
	
	@PostMapping(value="checkIdCard",consumes="application/json")
    public ResultModel saveAppInfo(@RequestBody Map<String,Object> params) 
	{
		if(Validator.isNullOrEmpty(params.get("name")) || Validator.isNullOrEmpty(params.get("cardno"))){
			return success(ResultDataEnum.PARAMS_ERROR);
		}
		if(develop)
		{
			//如果是开发模式下，则实名一直是成功的
			return success();
		}
		String name = params.get("name").toString();
		String cardno = params.get("cardno").toString();
		if(!IdcardUtil.validateCard(cardno)){
			return success(ResultDataEnum.IDCARD_ERROR);
		}
		log.info("==============name:{}====cardno:{}=================",name,cardno);
		
        return success(cardIdInfoService.checkIdCard(name, cardno));
    }
	
	
}
